#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

typedef pair<int, int> PII;

void merge(vector<PII>& segs)
{
    vector<PII> res;

    sort(segs.begin(), segs.end());

    int std = -2e9, ed = -2e9;
    for (auto it : segs)
    {
        if (ed < it.first)
        {
            if (ed != -2e9) res.push_back({ std, ed });

            std = it.first, ed = it.second;
        }
        else  ed = max(ed, it.second);
    }

    if (std != -2e9)  res.push_back({ std, ed });

    segs = res;

}

int main()
{
    int n;
    cin >> n;

    vector<PII> segs;
    for (int i = 0; i < n; i++)
    {
        int l, r;
        cin >> l >> r;

        segs.push_back({ l, r });
    }

    merge(segs);

    cout << segs.size() << endl;

    return 0;

}